package buzzerproxy; import buzzerproxy.CacheManager.CacheItem; import buzzerproxy.CacheManager.Serialization; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Enger */ public class TestClass { public static void main(String[] args) { // TODO code application logic here // BuzzerProxy proxy = new BuzzerProxy(); Google g = new Google(); IO io = new IO(); Http h = new Http(); CacheManager cache = new CacheManager(); Serialization ser = new Serialization(); GoogleResultParser gr = new GoogleResultParser(); String searchquery = h.searchQueryBeautify("Madonna"); String filetyp = "+.mp3+.wav+.flac+.wma"; // String uri = "http://www.google.de/stress.mp3"; // // if (io.isValidFileTyp(uri, filetyp)) { // System.out.println("ValidFileTyp: " + uri); // // } File f = new File(Constant.CACHEFILE); if (f.exists() && f.isFile()) { cache = ser.readCache(Constant.CACHEFILE); if (cache.contains(searchquery)) { System.out.println("Cache hit for: " + searchquery); ArrayList a = cache.getCacheArrayList(); ArrayList r = cache.getRangedCache(0, 10, ".wma", searchquery); System.out.println("\t Cache Hit: > got " + r.size() + " Results for "+searchquery); System.exit(1); } // if (cache.contains(searchquery)) { } // if (f.exists() && f.isFile()) { String googleResultString = g.getGoogleContent(searchquery, filetyp); ArrayList result = gr.parseResults(googleResultString, filetyp); try { int count = 0; for (ResultContainer res : result) { String ft = res.getFileTyp(); // wirft NullPointer verdammt String ul = res.getResultUrl(); long lc = res.getLastChecked(); String sz = res.getSizeOfUrlContent(); if (ft != null && ul != null && sz != null) { CacheItem it = new CacheItem(); it.setFilename(ft); it.setUrl(ul); it.setStoretime(lc); it.setContentlength(sz); cache.setCacheItem(it); System.out.println("\t [" + count + "] Result:" + res.getResultUrl()); count++; } // if ( ft != null && ul != null && lc != null && sz != null ){ } // for (ResultContainer res : result) { } catch (Exception e) { // Logger.getLogger(TestClass.class.getName()).log(Level.SEVERE, null, e); } ArrayList a = cache.getCacheArrayList(); cache.setCache(searchquery, a); ser.writeCache(Constant.CACHEFILE, cache); System.out.println("ArrayList Einträge:" + result.size()); } // public static void main(String[] args) { }